package com.zyz.M_File和IO流.IO流.节点流.InputStream和OutputStream;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

/**
 * @author: vick
 * @Date: 2025/4/8
 * @Description:
 * @version: 1.0
 */
public class Demo2 {
    public static void main(String[] args) throws IOException {
        //1. 创建 File对象
        File file = new File("read.txt");
        FileInputStream fileInputStream = new FileInputStream(file);
        //2. 定义变量，作为有效个数
        int len;
        //定义字节数组
        byte[] bytes = new byte[5];

        //循环读取
        while ((len = fileInputStream.read(bytes)) != -1) {
            //读取之后，将数组变成字符串打印
            String str = new String(bytes, 0, len);
            System.out.print(str);
        }
        //3. 关闭流
        fileInputStream.close();
    }
}
